package com.lwkjgf.workplace.base;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.lwkjgf.workplace.R;
import com.lwkjgf.workplace.utils.StatusBarUtil;


/**
 * mvp baseactivity 基类
 *  create by wind
 */
public abstract  class BaseMvpActivity<T extends IBasePresenter> extends BaseActivity{


    protected T mPresenter = null;
    public abstract int getLayoutId();
    public abstract void    initView();
    public abstract void  initData();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (!isTaskRoot()) {
            final Intent intent = getIntent();
            final String intentAction = intent.getAction();
            if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null &&
                    intentAction.equals(Intent.ACTION_MAIN)) {
                finish();
                return;
            }
        }
        setContentView(getLayoutId());
        StatusBarUtil.setTranslucentStatus(this);

        //防止进入页面弹出软键盘
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        initView();
        initData();
    }
    public void initTitle(String name){
        TextView titleName = findViewById(R.id.titleName);
        titleName.setText(name);
        ImageView back =  findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    public void initTitleNoImg(String name){
        TextView titleName = findViewById(R.id.titleName);
        titleName.setText(name);
    }
    @Override
    public void finish() {
        super.finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if( mPresenter != null){
            mPresenter.detachView();
            mPresenter = null;
        }

    }





}
